package core
{
import flash.utils.setTimeout;

import framework.dao.EntryUtil;

import isoengine.values.MapSkillRangeList;

import values.avatar.AvatarActionValue;
import values.avatar.AvatarAssetValue;
import values.avatar.AvatarEquipPositionValue;
import values.avatar.AvatarTemplateValue;
import values.avatar.AvatarTemplateValueList;
import values.avatar.AvatarTypeValue;
import values.avatar.AvatarTypeValueList;
import values.common.BonusValue;
import values.common.CostValue;
import values.effects.EffectSettingValue;
import values.inventory.BuildingItemInventoryValue;
import values.inventory.EquipmentItemInventoryValue;
import values.inventory.GroupedNumbericItemInventoryValue;
import values.inventory.InventoryValue;
import values.inventory.InventoryValueList;
import values.inventory.NumbericItemInventoryValue;
import values.inventory.OtherItemInventoryValue;
import values.inventory.UniqueItemInventoryValue;
import values.item.BuildingItemTemplateValue;
import values.item.ItemDropValue;
import values.item.ItemTemplateValue;
import values.item.ItemTemplateValueList;
import values.item.PackItemTemplateValue;
import values.item.ResourceItemTemplateValue;
import values.item.SkillBookItemTemplateValue;
import values.item.building.CaslteBuildingItemTemplateValue;
import values.item.building.FactoryBuildingItemTemplateValue;
import values.item.building.ModuleFunctionMapBuildingItemTemplateValue;
import values.level.AvatarLevelValue;
import values.level.AvatarLevelValueList;
import values.level.CityLevelValueList;
import values.level.DynamicLevelValue;
import values.level.LevelValue;
import values.map.MapObjectValue;
import values.map.MapValue;
import values.module.ModuleDataValue;
import values.module.ModuleValue;
import values.module.ModuleValueList;
import values.npcs.NpcTemplateValueList;
import values.other.GlobalValue;
import values.product.ProductTemplateValue;
import values.product.ProductTemplateValueList;
import values.quest.QuestEventValue;
import values.quest.QuestGoalTemplateValue;
import values.quest.QuestGroupTemplateValue;
import values.quest.QuestSettingValue;
import values.quest.QuestTemplateValue;
import values.quest.QuestTemplateValueList;
import values.shop.ShopConfigValue;
import values.shop.ShopGroupTypeValue;
import values.shop.ShopGroupValue;
import values.shop.ShopItemValue;
import values.skill.SkillTemplateValue;
import values.skill.SkillTemplateValueList;
import values.skill.SkillValue;
import values.tech.TechLevelValue;
import values.tech.TechRequirementValue;
import values.tech.TechTemplateValue;
import values.tech.TechTemplateValueList;
import values.tech.TechValue;
import values.ui_assets.UIAssetSettingValue;
import values.ui_assets.UIAssetValue;


public class DataObjectLib
{
	public function DataObjectLib()
	{
	}
	
	public static function initialize():void
	{
        ShopItemValue
        ShopGroupTypeValue
        ShopGroupValue
        ShopConfigValue
        
		ModuleDataValue;
		ItemTemplateValueList
		ItemTemplateValue
		ResourceItemTemplateValue
		BuildingItemTemplateValue
		FactoryBuildingItemTemplateValue
		CaslteBuildingItemTemplateValue
        PackItemTemplateValue
        SkillBookItemTemplateValue
		
		ProductTemplateValueList
		ProductTemplateValue		
		
		InventoryValueList
		InventoryValue
		UniqueItemInventoryValue
		NumbericItemInventoryValue
		GroupedNumbericItemInventoryValue
		EquipmentItemInventoryValue
		BuildingItemInventoryValue
        OtherItemInventoryValue
		
        AvatarLevelValueList
		LevelValue
		CityLevelValueList
		DynamicLevelValue
		AvatarLevelValue
		
		BonusValue
		CostValue
		
		ItemDropValue
        
        GlobalValue
		
		QuestTemplateValueList
		QuestTemplateValue
		QuestGoalTemplateValue
		
		QuestGroupTemplateValue
		QuestEventValue
		QuestSettingValue
		
		ModuleValueList
		ModuleValue
		
		UIAssetSettingValue
		UIAssetValue
		
		AvatarTemplateValueList
		AvatarTemplateValue
		AvatarAssetValue
		AvatarActionValue
		
		AvatarTypeValueList
		AvatarTypeValue
		AvatarEquipPositionValue
		
		SkillTemplateValueList
		SkillTemplateValue
		
		
		
		SkillValue

		
		TechTemplateValueList
		TechTemplateValue
		TechValue
		TechLevelValue
		TechRequirementValue	
		
		ModuleFunctionMapBuildingItemTemplateValue
		
		MapValue
		MapObjectValue
	}
	
	public static function setupData(completeCallBack:Function, configData:XML = null, questData:XML = null):void
	{
		var actions:XML = Configuration.configs["actions"];
		var factoryProduct:XML = Configuration.configs["factory_product"];
		var itemResource:XML = Configuration.configs["item_resource"];
		var itemBuilding:XML = Configuration.configs["item_building"];
		var itemEquipment:XML = Configuration.configs["item_equipment"];
        var itemPack:XML = Configuration.configs["item_pack"];
        var itemSkillBook:XML = Configuration.configs["item_skillbook"]
		var avatars:XML = Configuration.configs["avatars"];
		var avatarTypes:XML = Configuration.configs["avatar_types"];
		var skills:XML = Configuration.configs["skills"];
		var tech:XML = Configuration.configs["tech"];
		var gameSetting:XML = Configuration.configs["game_setting"];
		var questSetting:XML = Configuration.configs["quest"];
		var levelSetting:XML = Configuration.configs["game_level"];
		var mapSetting:XML = Configuration.configs["map"];
		var ui_assets:XML = Configuration.configs["ui_assets"];
		var effects:XML = Configuration.configs["effects"];
        var shopConfig:XML = Configuration.configs["shop"];
		var ranges:XML = Configuration.configs["ranges"];
		var npcs:XML = Configuration.configs["npcs"];
		
		groups.push(
			[
				{data:factoryProduct, classRef:ProductTemplateValueList},
				{data:itemResource, classRef:ItemTemplateValueList},
				{data:itemBuilding, classRef:ItemTemplateValueList},
				{data:itemEquipment, classRef:ItemTemplateValueList},
                {data:itemPack, classRef:ItemTemplateValueList},
                {data:itemSkillBook, classRef:ItemTemplateValueList},
			]
		);
		
		groups.push(
			[
				{data:skills.skills, classRef:SkillTemplateValueList}
			]
		);
		
		groups.push(
			[
				{data:ranges, classRef:MapSkillRangeList}
			]
		);
		
		groups.push(
			[
				{data:tech, classRef:TechTemplateValueList}
			]
		);
		
		groups.push(
			[
				{data:avatarTypes, classRef:AvatarTypeValueList}
			]
		);
		
		groups.push(
			[
				{data:levelSetting.avatar_levels, classRef:AvatarLevelValueList},
				{data:levelSetting.city_levels, classRef:CityLevelValueList}
			]
		);
		
		groups.push(
			[
				{data:avatars, classRef:AvatarTemplateValueList}
			]
		);
		
		groups.push(
			[
				{data:gameSetting.global, classRef:GlobalValue},
				{data:gameSetting.modules, classRef:ModuleValueList},
				{data:gameSetting.inventories, classRef:InventoryValueList}
			]
		);
		
		groups.push(
			[
				{data:questSetting, classRef:QuestTemplateValueList},
			]
		);
		
		groups.push(
			[
				{data:effects, classRef:EffectSettingValue},
				{data:ui_assets, classRef:UIAssetSettingValue},
			]
		);
        
        groups.push(
            [
                {data:shopConfig.items, classRef:ShopConfigValue},
                {data:shopConfig.groups, classRef:ShopConfigValue},
            ]
        );
		
		groups.push(
			[
				{data:npcs, classRef:NpcTemplateValueList},
			]
		);
		
		startSetup(completeCallBack);
	}
	
	private static var groups:Array = [];
	
	private static function startSetup(callBack:Function):void
	{
		var list:Array = groups.splice(0, 1)[0];
		for (var i:int = 0; i < list.length; i++)
		{
            if (list[i].classRef == ShopConfigValue)
            {
                trace(list);
            }
			EntryUtil.mapping(list[i].data, list[i].classRef);
		}		
		if (groups.length == 0) 
		{
			if (callBack != null)
			{
				callBack();
			}
			return;
		}		
		
		setTimeout(startSetup, 100, callBack);
	}
}
}


